package  
{
	import com.greensock.TweenMax;
	import org.flixel.FlxSprite;
	import com.greensock.easing.*;
	import org.flixel.FlxSprite;
	import org.flixel.FlxState;
	import org.flixel.FlxText;
	import org.flixel.FlxG;
	
	/**
	 * ...
	 * @author Enric Llagostera
	 */
	public class MenuState extends FlxState 
	{
		[Embed(source = "../assets/bigskull.png")] public const bigSkull:Class;
		[Embed(source = "../assets/BigWizard.png")] public const bigWizard:Class;
		[Embed(source = "../assets/Donthosemebro.png")] public const imgtitle:Class;
		[Embed(source = "../assets/OpeningScreen.png")] public const back:Class;
		[Embed(source = "../assets/getdimonds.png")] public const imgGetDimonds:Class;
		public var afterStart:Boolean = false;
		
		private var back1:FlxSprite;
		private var back2:FlxSprite;
		private var title:FlxSprite;
		private var bigskull:FlxSprite;
		private var bigwizard:FlxSprite;
		private var wizard:FlxSprite;
		
		
		private var bgSprite:FlxSprite;
		
		override public function create():void 
		{
			super.create();
			
			FlxG.playMusic(Registry.music, 0.4);
			
			Registry.scoreTeam1 = Registry.scoreTeam2 = 0;
			Registry.maxScore = 3;
			
			
			back1 = new FlxSprite(0, 0, back);
			back2 = new FlxSprite(FlxG.width, 0, back);
			add(back1);
			add(back2);
			title = new FlxSprite(0, -100, imgtitle);
			title.angle = -10
			TweenMax.to(title, 1, { y:60, ease:Elastic.easeIn, onComplete:DoTitleShake} );
			add(title);
			
			bigskull = new FlxSprite(400, 270, bigSkull);
			add(bigskull);
			bigwizard= new FlxSprite(100, 120, bigWizard);
			add(bigwizard);
			TweenMax.to(bigwizard, 0.2, { x : bigwizard.x + 10, repeat:100, yoyo:true} );
			bgSprite = new FlxSprite(0, 0);
			bgSprite.makeGraphic(FlxG.width, FlxG.height, 0xffffffff);
			
			//add(new FlxText(100, 100, 200, "DON'T HOSE ME BRO!!!! \n\n\n Press START!"));
		}
		
		private function DoTitleShake():void
		{
			TweenMax.to(title, 1, { angle:10, ease:Elastic.easeInOut, repeat: 100 , yoyo:true} );
		}
		
		override public function update():void 
		{
			back1.x --;
			back2.x --;
			bigskull.angle +=4;
			if (back1.x <= -FlxG.width) back1.x = FlxG.width;
			if (back2.x <= -FlxG.width) back2.x = FlxG.width;
			
			super.update();
			
			if (FlxG.keys.pressed("ONE")) {
				
				add(bgSprite);
				
				FlxG.shake(0.02, 2, startPlaying);
				
				// start get dimonds sounds
				
				add(bgSprite);
				var aux:FlxSprite = new FlxSprite(0, 0, imgGetDimonds);
				
				add(aux);
				
				
			}
		}
		
		public function startPlaying():void {
			FlxG.switchState(new PlayState);
		}
		
	}

}